package com.study.samsung.Service;

import cn.hutool.db.Session;
import com.study.samsung.Dao.GoodsDao;
import com.study.samsung.Entity.Commodity;
import com.study.samsung.Entity.Detail;
import com.study.samsung.Entity.ShoppingCart;

import java.util.ArrayList;
import java.util.List;

public class GoodsService {
    GoodsDao gdd = new GoodsDao();
    public List<ShoppingCart> queryAllcart(Integer uid) {
        List<ShoppingCart> shoppingCarts = gdd.queryAllcart(uid);

        shoppingCarts.forEach(x->{
            Detail detail = gdd.queryDetails(x.getSxid());
            x.setDetail(new Detail(x.getSxid(),detail.getXprice(),
                                     gdd.querycolor(detail.getYid()),
                                    gdd.querymemory(detail.getNid()),
                                    gdd.querycommodity(detail.getSid())));
        });
        return shoppingCarts;
    }

    public List<ShoppingCart> chuanOrder(int[] arr) {
        List<ShoppingCart> shoppingCarts = new ArrayList<ShoppingCart>();
        for (int i = 0; i < arr.length; i++) {
            shoppingCarts.add(gdd.queryShoppingCart(arr[i]));
        }
        return shoppingCarts;
    }




    public Integer updategnum(int aftergnum, int gid) {
        return gdd.updategnum(aftergnum,gid);
    }

    public Integer deletecart(int gid) {
        return gdd.deletecart(gid);
    }

    public Integer piliangdel(int[] arrs) {
        return gdd.piliangdel(arrs);
    }

    public List<Object> querycolormemory(int sxid) {
        Integer querysid = gdd.querysid(sxid);
        List<Object> arr=new ArrayList<>();
        arr.add(gdd.selectAllMemoryByCommodityId(querysid));
        arr.add(gdd.selectAllColorByCommodityId(querysid));
        arr.add(querysid);
        return arr;
    }

    public List<Object> nowcolormemory(String sxid) {
        return gdd.nowcolormemory(sxid);
    }

    public Integer querynewsxid(String memoryValue, String colorValue,Integer now_sid) {
        return gdd.querynewsxid(memoryValue,colorValue,now_sid);
    }

    public Integer updatesxid(Integer querynewsxid,Integer oldsxid) {
        return gdd.updatesxid(querynewsxid,oldsxid);
    }

    public Integer cartcount(Integer uid){
        return gdd.cartcount(uid);
    }
}
